﻿namespace Harness.Commands
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using mshtml;
    using SHDocVw;

    internal class SendKeysCommand : ICommand
    {
        #region Constants

        private const int KeyArgIndex = 0;

        #endregion

        #region Constants

        public void SyntaxCheck(IHarness harness, IEnumerable<object> args)
        {
            if (null == args.ElementAtOrDefault(KeyArgIndex))
            {
                throw new ArgumentNullException((KeyArgIndex + 1).ToString() + ":Keys");
            }
        }

        public dynamic Execute(IHarness harness, IEnumerable<object> args)
        {
            string keys = (args.ElementAtOrDefault(KeyArgIndex) ?? string.Empty).ToString();

            IE.SendKeys(keys);

            return null;
        }

        #endregion
    }
}
